package com.example.websocket.myWebSocket;

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

@ServerEndpoint("/websocket")
public class MyWebSocket {
    /**
     * Auther sun
     * DATE 2022/5/1 12:31
     * VERSION 1.0
     */

    @OnOpen
    public void onOpen(Session session) throws IOException {
        System.out.println("websocket 已连接 " + session);
        session.getBasicRemote().sendText("欢迎登录");

    }
    @OnClose
    public void onClose(Session session) {
        System.out.println("websocket 已关闭 " + session);
    }
    @OnMessage
    public void onMessage(String message, Session session) throws IOException{
        System.out.println("收到客户端发来的消息" + message);

        session.getBasicRemote().sendText("消息已收到");
    }


}
